<?php
namespace app\ucentre\validate;

use think\Validate;

class User extends Validate
{
    protected $rule =   [
    	'password' => 'checkPwd',
    	'repassword' => 'confirm:password',
    	'mobile' => 'mobile',
    	'email' => 'email',
    	'file' => 'image:200,200,jpg|checkPortrait',//
    ];
    
    protected $message  =   [
    	'username.require' => '用户名不能为空',
    	'password.require' => '密码不能为空',
    ];

    protected function checkPwd($value, $rule, $data=[])
    {
	
        /*if(!captcha_check($value)){
        	return '验证码有误';
        }*/
    	return true;
    }
    
    //验证头像
    protected function checkPortrait($value, $rule, $data=[])
    {
    	
		if($value->getSize() > 51200){
			return '上传文件大小不符';
		}
		$suffix = substr($value->getOriginalName(), -4);
        if($suffix<>'.jpg'){
        	return '上传文件后缀有误';
        }
    	return true;
    }
}
?>